/*
 * watch_data_packet.cpp
 *
 *  Created on: 30.06.2013
 *      Author: SpirTanol
 */

#include "packets/watch_data_packet.h"

// STD
#include <string.h>
//=========================================================================================
WatchDataPacket::WatchDataPacket()
{
	init();
}

WatchDataPacket::WatchDataPacket(const WatchDataPacket *packet)
{
	init();
	memcpy(oData, packet->oData, R_SIZE * sizeof(ushort));
}

WatchDataPacket::~WatchDataPacket()
{

}
//=========================================================================================
void WatchDataPacket::init()
{
	addPart(Part(oData, 17, 33));
	addPart(Part(&oData[R_WORK_TIME], 1, 170));
}
//=========================================================================================
bool WatchDataPacket::outputState(Output out) const
{
	bool state = false;
	switch (out)
	{
	case O_POWER:
		state = (oData[R_OUTPUT_STATE] & 1) != 0;
		break;
	case O_APPEND:
		state = (oData[R_OUTPUT_STATE] & 2) != 0;
		break;
	case O_GENERAL:
		state = ((oData[R_OUTPUT_STATE] >> 15) & 1) != 0;
		break;
	}

	return state;
}
//=========================================================================================
WatchDataPacket80::WatchDataPacket80(const WatchDataPacket80 *packet) : WatchDataPacket(packet)
{
	init();
	oStartCount = packet->oStartCount;
}
